package com.qst.action.question;

import com.qst.BaseServlet;
import com.qst.service.AssessmentService;
import com.qst.service.QuestionService;
import com.qst.service.impl.ServiceFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//@WebServlet("/question/save.action")
public class SaveServlet extends BaseServlet {

    private AssessmentService assessmentService = ServiceFactory.getService(AssessmentService.class);
    private QuestionService questionService = ServiceFactory.getService(QuestionService.class);

    @Override
    protected void doAction(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        Question question = QuestionHelper.createQuestion(req);
//        List<Choice> choices = QuestionHelper.createChoice(req);
//        try {
//            User currentUser = (User) req.getSession().getAttribute(Constant.CURRENT_USER);
//            question.setUserId(currentUser.getId());
//            questionService.save(question, choices);
//            addMessage(req, "试题保存到数据库中");
//            WebUtil.redirect(req, resp, "/question/dimension.action?id=" + question.getId());
//        } catch (ExamException ex) {
//            System.out.println(ex);
//            addError(req, ex.getMessage());
//            req.setAttribute("question", question);
//            req.setAttribute("choices", choices);
//            req.setAttribute("assessment", assessmentService.findAssessmentById(question.getAssessmentId()));
//            WebUtil.forward(req, resp, "/question/create.jsp");
//        }
    }
}
